// 登录页面服务逻辑

import type { LoginForm, LoginResponse } from './types'

const API_BASE_URL = 'http://localhost:3000/api'

// 登录
export const login = async (form: LoginForm): Promise<{ token: string; user: { id: number; username: string } }> => {
  const res = await fetch(`${API_BASE_URL}/login`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(form)
  })

  if (!res.ok) {
    const error = await res.json()
    throw new Error(error.message || '登录失败')
  }

  const response = await res.json()
  return response.data
} 